<template>
	<view>
		<cu-custom :isBack="true" :bgColor="'bg-'+ theme.themeColor">
			<block slot="backText">返回</block>
			<block slot="content">降价通知</block>
		</cu-custom>
		<form @submit="onSub">
			<view class="cu-form-group">
				<view class="title">当前价格</view>
				<text class="text-right text-price text-red"> {{form.salesPrice}}</text>
			</view>
			<view class="cu-form-group">
				<view class="title">期望价格</view>
				<input placeholder="请输入期望价格" class="text-right" type="number" v-model="form.expectedPrice"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">通知方式</view>
				<text class="text-sm text-gray">采用短信通知，小程序授权后会有订阅消息哦</text>
			</view>
			<view>
				<button class="cu-btn shadow-blur block margin-sm round bottom-btn bg-red" formType="submit">确定</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		save
	} from '@/api/goodsdownpricenotify.js';
	export default {
		data() {
			return {
				theme: getApp().globalData.theme,
				form: {
					salesPrice: 0,
					spuId: ''
				}
			}
		},
		onLoad(options) {
			this.form.salesPrice = options.salesPrice;
			this.form.spuId = options.spuId;
		},

		methods: {
			onkeyup(value) {
				var price = value.toString().match(/^\d+(.\d{1,2})?$/)
				this.$nextTick(() => {
					this.form.expectedPrice = price && price[0]
				})

			},
			onSub(e) {
				if (!this.form.expectedPrice || this.form.expectedPrice <= 0) {
					uni.showToast({
						title: '请输入期望价格',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				if (this.form.expectedPrice >= this.form.salesPrice) {
					uni.showToast({
						title: '期望价格必须低于当前价格',
						icon: 'none',
						duration: 3000
					});
					return;
				}
				save(this.form).then(response => {
					uni.showToast({
						title: '提交成功',
						icon: 'success',
						duration: 2000
					});
					uni.navigateBack();

				})
			}
		}
	}
</script>

<style lang="scss">
</style>
